gridFromPoints <- function(d, cellsize, buffer) {
    bbox <- summary(d)$bbox
    xmin <- bbox[1] - buffer
    ymin <- bbox[2] - buffer
    xrange <- bbox[3]-bbox[1]
    yrange <- bbox[4]-bbox[2]
    xdim <- ceiling((xrange+buffer*2)/cellsize)
    ydim <- ceiling((yrange+buffer*2)/cellsize)
    egrid<-cbind(expand.grid(x=seq(xmin,xmin+(cellsize*xdim),by=cellsize),
                        y=seq(ymin,ymin+(cellsize*ydim),by=cellsize),
                        d=c(0)))
    coordinates(egrid)<-c("x","y")
    gridded(egrid)<-TRUE
    proj4string(egrid)<-CRS(proj4string(d))
    egrid$x <- coordinates(egrid)[,1]
    egrid$y <- coordinates(egrid)[,2]
    return(egrid)
}

plotInterp <- function(result,d,column="var1.pred") {
 plt = spplot(result[column], col.regions=bpy.colors(),
          scales=list(draw=TRUE, cex=0.7),
          sp.layout=list("sp.points", col="black",pch="+",obj=d)) 
 print(plt)
}
